<!--
**********************************************************
* @Author: 张小平
* @Date:   2024-05-01
* @Email:  qqshuqian@163.com
* @Last modified: 最后修改日期
* @Description: 文件描述
**********************************************************
-->
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        v-model="form"
        v-model:search="searchForm"
        v-model:page="page"
        :option="option"
        :data="tableData"
        :permission="getPermission"
        v-bind="bindVal"
        v-on="onEvent"
        :before-open="beforeOpen"
      />
    </basic-container>
  </div>
</template>

<script>
  import crud from "@/framework-core/mixins/crud";
  import { tableOption } from "./datasource";

export default {
  name: "CodeGenerator",
  mixins: [crud],
  data() {
    return {
      pageConfig:{"url":"sys/datasource"},
      tableLoading: false,
      tableData: [],
      option: tableOption,
      form: {},

    };
  },
  watch: {
    "form.confType"() {
      this.$refs.crud.option.column.filter((item) => {
        if (item.prop === "url") {
          item.addDisplay = this.form.confType === 1;
          item.editDisplay = this.form.confType === 1;
        }

        if (item.prop === "host") {
          item.addDisplay = this.form.confType !== 1;
          item.editDisplay = this.form.confType !== 1;
        }

        if (item.prop === "port") {
          item.addDisplay = this.form.confType !== 1;
          item.editDisplay = this.form.confType !== 1;
        }

        if (item.prop === "dbName") {
          item.addDisplay = this.form.confType !== 1;
          item.editDisplay = this.form.confType !== 1;
        }

      });
    },
    "form.dbType"() {
      this.$refs.crud.option.column.filter((item) => {

        if (item.prop === "port") {
          if (this.form.dbType === "mysql") {
            this.form.port = 3306;
          }

          if (this.form.dbType === "oracle") {
            this.form.port = 1521;
          }

          if (this.form.dbType === "pg") {
            this.form.port = 5432;
          }

          if (this.form.dbType === "db2") {
            this.form.port = 50000;
          }
        }
      });
    },
  },

  computed: {
    ...mapState({
      permissions: (state) => state.user.permission,
    }),
  },
  methods: {
    getPermission:function(key, row, index) {
      return this.getCommPermission(key, row, index);
    }
  },
};
</script>

<style lang="scss" scoped>
</style>
